import requests

url='http://www.baidu.com'

#在有身份验证的网站上 要修改请求头 来正常访问网站
headers={
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36'
}

res=requests.get(url=url,headers=headers)
res.encoding = 'utf-8'
status_code=res.status_code
if status_code ==200:
    print('请求成功!')
    with open('./temp.html','w',encoding='utf-8') as fp:
        fp.write(res.text)